<template lang="html">
  <div class="dialog-share--join">
    <span  class="close col-all-center" @click="close"><van-icon name="cross" /></span>
    <img class="canvas-img" :src="canvasImg" alt="" v-if="canvasImg">
    <div class="canvas-wrapper" ref="canvas" v-else>
      <div class="share-title flex">
         <!-- <img  v-if="wxName" class="wxImg" :src="avator"> -->
         <div>
           <p class="join-title--text">{{'名字'}}</p>
           <p class="join-title--text">在<span class="ellipsis">{{'minzi'}}</span>中参与了互动：</p>
         </div>
         <i class="iconfont iconhaibao-yinhao"></i>
      </div>
      <div class="share-content">
        <!-- <p class="content" v-html="content"></p>
        <img v-if="img" :src="img"> -->
      </div>
      <div class="share-footer">
        <i class="iconfont iconhaibao-jiaobiao"></i>
        <div class="code-content">
          <p class="code-text">长按识别二维码</p>
          <div id="joinCode"></div>
        </div>
      </div>
    </div>
    <div id="qrcodeJoin"></div>
    <!-- <loading v-show="!canvasImg"></loading> -->
    <div class="share-tip">长按保存图片，发送至好友或朋友圈</div>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import Cookies from 'js-cookie'
import { replaceReturn } from 'utils/tool'
import { QRCode } from 'utils/qrcode'
import loading from 'components/Dialog/loading'
import html2canvas from 'html2canvas'

export default {
  components: {
    'loading': loading
  },
  data () {
    return {
      visible: false,
      canvasImg: '',
    }
  },
  mounted () {
  },
  props: ['detail'],
  computed: {

  },
  watch: {
  },
  created () {
    this.createImg()
  },
  methods: {
    createImg () {
      const _this = this
      setTimeout(() => {
        let _canvas = _this.$refs.canvas;
        // 解决不清晰问题
        const opts = {
          y: window.scrollY,
          backgroundColor: 'transparent',
          useCORS: true, // 允许跨域
          // allowTaint: true
        };
        html2canvas(_canvas, opts).then((canvas) => {
          _this.canvasImg = canvas.toDataURL()
        });
      }, 2000)
    },
    close () {
      this.canvasImg = ''
      let obj = {
        show: false,
        type: '',
        msg: {}
      }
      this.$emit('close')
      //   this.UPDATE_SHAREINFO(Object.assign(this.shareInfo, obj))
    },
  }
}
</script>

<style lang="scss">
@import "assets/scss/index.scss";
.dialog-share--join {
  width: 100%;
  height: 100%;
  padding: 0 0 0.88rem;
  position: fixed;
  transform: none;
  background: rgba(#000, 0.8);
  z-index: 200000;
  left: 0 !important;
  top: 0 !important;
  overflow: auto;
  -webkit-overflow-scrolling: touch;

  .close {
    width: 0.56rem;
    height: 0.56rem;
    position: absolute;
    right: 0.3rem;
    top: 0.3rem;
    z-index: 110000;
    .iconfont {
      color: #fff;
      font-size: 0.32rem;
    }
  }
  .canvas-img {
    display: block;
    width: 7.5rem;
  }
  .canvas-wrapper {
    padding: 0.4rem;

    .share-title {
      position: relative;
      .wxImg {
        width: 0.9rem;
        height: 0.9rem;
        border-radius: 50%;
        margin-right: 0.1rem;
      }
      .join-title--text {
        font-size: 0.32rem;
        text-align: left;
        display: flex;
        span {
          max-width: 2rem;
          display: inline-block;
          margin: 0 0.1rem;
        }
      }
      .iconfont {
        position: absolute;
        top: 0;
        right: 0;
      }
    }
    .share-content {
      margin: 0.4rem 0 0.28rem 0;
      padding: 0.4rem;

      .content {
        text-align: left;
        line-height: 0.4rem;
        word-break: break-all;

        margin-bottom: 0.2rem;
      }
      img {
        width: 100%;
        display: block;
      }
    }
    .share-footer {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      height: 1.2rem;
      // padding: 0 0.4rem 0.4rem 0.4rem;

      font-size: 0.12rem;
    }
    .code-content {
      width: 3.8rem;
      height: 1.2rem;
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      height: 1.2rem;
      .code-text {
        font-size: 0.28rem;
      }
      #joinCode {
        width: 1.2rem;
        height: 1.2rem;
        background-color: #fff;
        padding: 0.04rem;
        img {
          width: 100%;
          display: block;
        }
      }
    }
  }
}
.share-tip {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0.88rem;
  line-height: 0.88rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 0.28rem;
}
</style>
